﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>老师设定</title>
<style type="text/css">
#tb tr td {
	border: 1px;
	border-color: black;
	border-style: solid;
	text-align: center;
}
#tb tr {
	height: 20px;
}
</style>
<script type="text/javascript">
	var mainform;
	var viewType = "${viewType}";
	var id = "${id}";
	var courseId = $("#courseId").val();
	var dptId = $("#dptId").val();
	var teaId = $("#teaId").val();
	var gradeId = $("#gradeId").val();
	var classId = $("#classId").val();
	var valueList = "";
	var strList = '${ strJson }';
	var indexList = '${indexJson}';

	$(function() {

		mainform = $("#mainform");
		mainform.ligerForm();
		
		$.metadata.setType("attr", "validate");
        LG.validate(mainform);
        
        $("#classId").attr("disabled","disabled");
        $("#gradeId").attr("disabled","disabled");

		//渲染按钮
		LG.setFormDefaultBtn(cancel, viewType == "detail" ? null : save);

		var Lobj = document.getElementsByName('chbox');

		$.each(eval('('+strList+')'), function(index, data) {
			var $v = $(Lobj[index]);
			var manage = $v.ligerCheckBox();
			if (data == "true") {
				manage.setEnabled();
			} else {
				manage.setDisabled();
			}
		});

		$.each(eval('('+indexList+')'), function(i, d) {
			var $v = $(Lobj[d]);
			var manage = $v.ligerCheckBox();
			if(!manage.getValue())
				manage.setEnabled();
			else
				manage.setDisabled();
		});

	});

	function save() {
		valueList = "";
		var flag=false;
		var obj = document.getElementsByName('chbox');
		for ( var i = 0; i < obj.length; i++) {
			if(obj[i].checked) flag=true;
			valueList += obj[i].checked + ",";
		}
		document.getElementById("values").value = valueList;

		var unSelect="";
    	if($("#courseId").val()=='-1'){
    		unSelect+="课程名称、";
    	}
    	if($("#dptId").val()=='-1'){
    		unSelect+="科系名称、";
    	}
    	if($("#teaId").val()=='-1'){
    		unSelect+="教师名称、";
    	}
    	if($("#gradeId").val()=='-1'){
    		unSelect+="年级名称、";
    	}
    	if($("#classId").val()=='-1'){
    		unSelect+="班级名称、";
    	}
    	
    	if(unSelect!=""){
    		LG.showError('请先选择: ' + unSelect);
    	}else{
    		
    		if(flag){
    			LG.submitForm(mainform, function(result) {
        			if (typeof (result) == "string") {
        				result = eval("(" + result + ")");
        			}
        			if (!result.success) {
        				LG.showError('错误:' + result.message);
        			} else {
        				LG.showSuccess('保存成功', function() {
        					LG.callParent("btableList");

        				});
        			}
        		});
    		}else{
    			LG.showError('请先勾选课节:');
    		}
    		
    	}
		
	}
	function cancel() {
		var win = window.parent || window;
		if (win.dialog) {
			win.dialog.close();
		}
	}
	function onGradeChange(){
			if($("#gradeId").val()!='-1'){
				if($("#dptId").val()!='-1'){
					$("#classId").attr("disabled",false);
					resetOptions($("#dptId").find("option:selected").text()
							,$("#gradeId").find("option:selected").text());
		    	}
	    	}
	    }
	    
	    function onDeptChange(){
	    	if($("#dptId").val()!='-1'){
	    		$("#gradeId").attr("disabled",false);
				if($("#gradeId").val()!='-1'){
					$("#classId").attr("disabled",false);
					resetOptions($("#dptId").find("option:selected").text()
							,$("#gradeId").find("option:selected").text());
		    	}
	    	}
	    }
	    
	    function resetOptions(t1,t2){
	    	document.getElementById('classId').options.length = 0;  //清空原有的option 
	    	var str="<option value='-1'>请选择</option>";  
	    	var st='${clas}';
	    	var claList= eval('('+st+')'); 
	    	jQuery.each(claList, function(i,item){
	    		if(t1==item.deptTitle && t2==item.gradeTitle){
	    			str+="<option value='"+item.clsId+"'>"+item.clsTitle+"</option>"
	    		}
	    	});     

	    	$("#classId").html(str);
	    	
	    }
</script>
</head>

<body>
	<form name="mainform" method="post" id="mainform"
		action="${ctx }/qso/btable/save">
		<input type="hidden" name="viewType" value="${viewType}" /> 
		<input type="hidden" name="id" value="${id}" /> 
		<input type="hidden" id="values" name="values" value="" />
		
		<table cellpadding="0" cellspacing="0" class="l-table-edit"
			style="width: 90%; margin-top: 10px; margin-left: 15px;">
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 20%">课程名称:</td>
				<td align="left" class="l-table-edit-td" style="width: 30%"><select
					name="courseId" id="courseId" ltype="select"
					validate="{required:true}" style="width: 100%">
						<option value="-1">请选择</option>
						<c:forEach items="${courses}" var="course">
							<c:choose>
								<c:when test="${command.couid.id eq course.id}">
									<option value="${course.id}" selected="selected">${course.title}</option>
								</c:when>
								<c:otherwise>
									<option value="${course.id}">${course.title}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
				</select></td>
				<td align="right" class="l-table-edit-td" style="width: 20%">教师姓名:</td>
				<td align="left" class="l-table-edit-td" style="width: 30%"><select
					name="teaId" id="teaId" ltype="select" validate="{required:true}"
					style="width: 100%">
						<option value="-1">请选择</option>
						<c:forEach items="${teachers}" var="teacher">
							<c:choose>
								<c:when test="${command.teaid.terId eq teacher.terId}">
									<option value="${teacher.terId}" selected="selected">${teacher.terName}</option>
								</c:when>
								<c:otherwise>
									<option value="${teacher.terId}">${teacher.terName}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
				</select></td>
			</tr>
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 20%">科系:</td>
				<td align="left" class="l-table-edit-td" style="width: 30%"><select
					name="dptId" id="dptId" ltype="select" validate="{required:true}"
					style="width: 100%" onchange="onDeptChange()">
						<option value="-1">请选择</option>
						<c:forEach items="${depts}" var="dept">
							<c:choose>
								<c:when test="${command.dptid.id eq dept.id}">
									<option value="${dept.id}" selected="selected">${dept.title}</option>
								</c:when>
								<c:otherwise>
									<option value="${dept.id}">${dept.title}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
				</select></td>
				<td align="right" class="l-table-edit-td" style="width: 20%">年级:</td>
				<td align="left" class="l-table-edit-td" style="width: 30%"><select
					name="gradeId" id="gradeId" ltype="select"
					validate="{required:true}" style="width: 100%" onchange="onGradeChange()">
						<option value="-1">请选择</option>
						<c:forEach items="${grades}" var="grade">
							<c:choose>
								<c:when test="${command.gradeid.gradeId eq grade.gradeId}">
									<option value="${grade.gradeId}" selected="selected">${grade.gradeTitle}</option>
								</c:when>
								<c:otherwise>
									<option value="${grade.gradeId}">${grade.gradeTitle}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
				</select></td>
			</tr>
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 20%">班级:</td>
				<td align="left" class="l-table-edit-td" style="width: 30%"><select
					name="classId" id="classId" ltype="select"
					validate="{required:true}" style="width: 100%" disabled="disabled">
						<option value="-1">请选择</option>
						<c:forEach items="${clas}" var="cla">
							<c:choose>
								<c:when test="${command.claid.clsId eq cla.clsId}">
									<option value="${cla.clsId}" selected="selected">${cla.clsTitle}</option>
								</c:when>
								<c:otherwise>
									<option value="${cla.clsId}">${cla.clsTitle}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
				</select></td>
			</tr>
		</table>

		<div style="margin-top: 10px; margin-left: 55px;">上课时间:</div>
		<table id="tb" cellpadding="0" cellspacing="0" class="l-table-edit"
			style="width: 90%; margin-top: 10px; margin-left: 55px;">
			<tr>
				<td width="80px">课节</td>
				<td>一</td>
				<td>二</td>
				<td>三</td>
				<td>四</td>
				<td>五</td>
				<td>六</td>
				<td>日</td>
			</tr>
			<tr>
				<td>第一节</td>

				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第二节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第三节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第四节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第五节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第六节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第七节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第八节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第九节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
			<tr>
				<td>第十节</td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
				<td><input type="checkbox" name="chbox" /></td>
			</tr>
		</table>
	</form>
</body>
</html>
